package com.xca.gsondemo.common;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.xca.gsondemo.R;

/**
 * 自定义Toast
 */
public class CustomToast {
    private TextView mText;
    private Toast mToast;

    public CustomToast(Activity context) {
        init(context);
    }

    private void init(Activity ctx) {
        if (ctx != null) {
            LayoutInflater layoutInflater = ctx.getLayoutInflater();
            View view = layoutInflater.inflate(R.layout.custom_toast, null);
            mText = view.findViewById(R.id.toast_text);
            mToast = new Toast(ctx);
            mToast.setView(view);
        }
    }

    public void setDuration(int d) {
        mToast.setDuration(d);
    }

    public void setText(String text) {
        mText.setText(text);
    }

    public void show() {
        mToast.show();
    }

    public void cancel() {
        mToast.cancel();
    }
}
